export function isAuth(tableName, key) {
  let role = localStorage.getItem("UserTableName");
  let menus = [
    {
        "backMenu": [
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-brand",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "工作人员",
                        "menuJump": "列表",
                        "tableName": "gongzuorenyuan"
                    }
                ],
                "menu": "工作人员管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-present",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "农产品分类",
                        "menuJump": "列表",
                        "tableName": "chanpinfenlei"
                    }
                ],
                "menu": "农产品分类管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-attentionfavor",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "供应商",
                        "menuJump": "列表",
                        "tableName": "gongyingshang"
                    }
                ],
                "menu": "供应商管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "农产品信息",
                        "menuJump": "列表",
                        "tableName": "chanpinxinxi"
                    }
                ],
                "menu": "农产品信息管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "农产品抽检",
                        "menuJump": "列表",
                        "tableName": "chanpinchoujian"
                    }
                ],
                "menu": "农产品抽检管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-addressbook",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "原料溯源",
                        "menuJump": "列表",
                        "tableName": "yuanliaosuyuan"
                    }
                ],
                "menu": "原料溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "生产溯源",
                        "menuJump": "列表",
                        "tableName": "shengchansuyuan"
                    }
                ],
                "menu": "生产溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pay",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "仓储溯源",
                        "menuJump": "列表",
                        "tableName": "cangchusuyuan"
                    }
                ],
                "menu": "仓储溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-keyboard",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "物流溯源",
                        "menuJump": "列表",
                        "tableName": "wuliusuyuan"
                    }
                ],
                "menu": "物流溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-newshot",
                        "buttons": [
                            "查看",
                            "修改"
                        ],
                        "menu": "系统简介",
                        "tableName": "systemintro"
                    },
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "查看",
                            "修改"
                        ],
                        "menu": "轮播图管理",
                        "tableName": "config"
                    },
                    {
                        "appFrontIcon": "cuIcon-news",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "系统公告",
                        "tableName": "news"
                    },
                    {
                        "appFrontIcon": "cuIcon-service",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "留言反馈",
                        "tableName": "chat"
                    },
                    {
                        "appFrontIcon": "cuIcon-taxi",
                        "buttons": [
                            "查看",
                            "修改"
                        ],
                        "menu": "关于我们",
                        "tableName": "aboutus"
                    }
                ],
                "menu": "系统管理"
            }
        ],
        "frontMenu": [
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-form",
                        "buttons": [
                            "查看",
                            "原料;生产;仓储;物流"
                        ],
                        "menu": "农产品信息列表",
                        "menuJump": "列表",
                        "tableName": "chanpinxinxi"
                    }
                ],
                "menu": "农产品信息模块"
            }
        ],
        "hasBackLogin": "是",
        "hasBackRegister": "否",
        "hasFrontLogin": "否",
        "hasFrontRegister": "否",
        "roleName": "管理员",
        "tableName": "users"
    },
    {
        "backMenu": [
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "新增",
                            "查看",
                            "修改",
                            "删除",
                            "查看评论",
                            "原料",
                            "生产",
                            "仓储",
                            "物流",
                            "抽检"
                        ],
                        "menu": "农产品信息",
                        "menuJump": "列表",
                        "tableName": "chanpinxinxi"
                    }
                ],
                "menu": "农产品信息管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "农产品抽检",
                        "menuJump": "列表",
                        "tableName": "chanpinchoujian"
                    }
                ],
                "menu": "农产品抽检管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-addressbook",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "原料溯源",
                        "menuJump": "列表",
                        "tableName": "yuanliaosuyuan"
                    }
                ],
                "menu": "原料溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pic",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "生产溯源",
                        "menuJump": "列表",
                        "tableName": "shengchansuyuan"
                    }
                ],
                "menu": "生产溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-pay",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "仓储溯源",
                        "menuJump": "列表",
                        "tableName": "cangchusuyuan"
                    }
                ],
                "menu": "仓储溯源管理"
            },
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-keyboard",
                        "buttons": [
                            "查看",
                            "修改",
                            "删除"
                        ],
                        "menu": "物流溯源",
                        "menuJump": "列表",
                        "tableName": "wuliusuyuan"
                    }
                ],
                "menu": "物流溯源管理"
            }
        ],
        "frontMenu": [
            {
                "child": [
                    {
                        "appFrontIcon": "cuIcon-form",
                        "buttons": [
                            "查看",
                            "原料;生产;仓储;物流"
                        ],
                        "menu": "农产品信息列表",
                        "menuJump": "列表",
                        "tableName": "chanpinxinxi"
                    }
                ],
                "menu": "农产品信息模块"
            }
        ],
        "hasBackLogin": "是",
        "hasBackRegister": "否",
        "hasFrontLogin": "是",
        "hasFrontRegister": "是",
        "roleName": "工作人员",
        "tableName": "gongzuorenyuan"
    }
];
  for(let i=0;i<menus.length;i++){
    if(menus[i].tableName==role){
      for(let j=0;j<menus[i].frontMenu.length;j++){
          for(let k=0;k<menus[i].frontMenu[j].child.length;k++){
            if(tableName==menus[i].frontMenu[j].child[k].tableName){
              let buttons = menus[i].frontMenu[j].child[k].buttons.join(',');
              return buttons.indexOf(key) !== -1 || false
            }
          }
      }
    }
  }
  return false;
}

/**
 *  * 获取当前时间（yyyy-MM-dd hh:mm:ss）
 *   */
export function getCurDateTime() {
    let currentTime = new Date(),
    year = currentTime.getFullYear(),
    month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
    day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate(),
    hour = currentTime.getHours(),
    minute = currentTime.getMinutes(),
    second = currentTime.getSeconds();
    return year + "-" + month + "-" + day + " " +hour +":" +minute+":"+second;
}

/**
 *  * 获取当前日期（yyyy-MM-dd）
 *   */
export function getCurDate() {
    let currentTime = new Date(),
    year = currentTime.getFullYear(),
    month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
    day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate();
    return year + "-" + month + "-" + day;
}
